package ro.ase.catalog.security.dao.hibernate;

import ro.ase.catalog.beans.*;
import ro.ase.catalog.dao.hibernate.GenericDAOImpl;
import ro.ase.catalog.security.dao.ITeacherDisciplineClassDAO;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Ioana
 * Date: 5/14/14
 * Time: 12:12 AM
 * To change this template use File | Settings | File Templates.
 */
public class TeacherDisciplineClassDAOImpl extends GenericDAOImpl<TeacherDisciplineClass, Integer> implements ITeacherDisciplineClassDAO {
    public Teacher checkAssociation(String discipline, String cls) {
        List<Teacher> teacherList=getHibernateTemplate().find("select t.teacher from TeacherDisciplineClass t where t.discipline.name = ? and t.aSchoolClass.name=?", new Object[]{discipline, cls} );
        if(teacherList.size()!=0)
        return teacherList.get(0);
        else return null;
    }

    public Discipline findDisciplineByName(String discipline) {
        List<Discipline> disciplineList=getHibernateTemplate().find("select t from Discipline t where t.name = ? ", discipline );
        return disciplineList.get(0);
    }

    public List<Discipline> getAllDisciplines() {
        List<Discipline> disciplineList=getHibernateTemplate().find("select t from Discipline t ");
        return disciplineList;  }

    public List<TeacherDisciplineClass> getAllClassByTeacher(Teacher teacher) {
        List<TeacherDisciplineClass> teacherDisciplineClasses=getHibernateTemplate().find("select tdc from TeacherDisciplineClass tdc where tdc.teacher.id = ?", teacher.getId());
        return teacherDisciplineClasses;
    }

    public List<TeacherDisciplineClass> getAllDisciplinesByStudent(Student student) {
        List<TeacherDisciplineClass> teacherDisciplineClasses=getHibernateTemplate().find("select tdc from TeacherDisciplineClass tdc where tdc.aSchoolClass = ?", student.getSchoolClass());
        return teacherDisciplineClasses;
    }

    public TeacherDisciplineClass getByClassAndTeacher(Teacher teacher, SchoolClass schoolClass) {
        List<TeacherDisciplineClass> teacherDisciplineClasses=getHibernateTemplate().find("select tdc from TeacherDisciplineClass tdc where tdc.teacher= ? and tdc.aSchoolClass=?",new Object[]{teacher,schoolClass});
        if(teacherDisciplineClasses.size()>0)
            return teacherDisciplineClasses.get(0);
        else
            return null;

    }

}
